<?php
class IndexController extends CommonController {
	public function index()
	{
		$this->display();
	}
	public function setting(){
		if($this->isGet()){
			$this->display();
		}else{
			file_put_contents(CONFIG_PATH.'/config.setting.php','<?php return ' . var_export ( $_POST, true ) . ';');
			$this->success('修改成功',U('setting'));
		}
	}
	public function updatePwd(){
		if($this->isGet()){
			$this->display();
		}else{
			$old_password=md5($_POST['old_password']);
			if($_SESSION['admin']['password']!=$old_password){
				$this->error('原密码不正确');
			}
			$new_password=md5($_POST['new_password']);
			$new_repassword=md5($_POST['new_repassword']);
			if($new_password!=$new_repassword){
				$this->error('新密码不一致');
			}
			$u['id']=$_SESSION['admin']['id'];
			$u['password']=$new_password;
			if(M('Admin')->update($u)){
				$_SESSION['admin']['password']=$new_password;
				$this->success('修改密码成功');
			}else{
				$this->error('修改密码失败');
			}
		}
	}
}